﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Sworm;

namespace SwormTests.Misc
{
    public class metadata_exceptions : TestBase
    {
        public metadata_exceptions(DbToTest db) : base(db) { }

        protected override bool ShouldRecreateTablesAutomatically { get { return false; } }

        private void BuildMetadata<T>()
        {
            MetadataBuider.TableDataFor(typeof(T));
        }

        class multiple_pks
        {
            [Sworm.Column(IsPrimaryKey = true)]
            public int first { get; set; }

            [Sworm.Column(IsPrimaryKey = true)]
            public int second { get; set; }
        }

        [Test]
        [ExpectedException(typeof(InvalidMetadataException))]
        public void cannot_have_multiple_pks()
        {
            try
            {
                BuildMetadata<multiple_pks>();
            }
            catch (InvalidMetadataException ex)
            {
                Assert.IsTrue(ex.Message.StartsWith("cannot specify more than one primary key"));
                throw;
            }
        }
    }
}
